package com.wgy.day42Jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * Created by pc on 2021/1/11 20:34
 * Description: LearningJava
 */
/*Jsoup对象功能*/
public class JsoupDemo2 {
    public static void main(String[] args) throws IOException {
        //1.parse​(File in, String charsetName)：解析xml或html文件的
        Document document = Jsoup.parse(new File("student.xml"), "utf-8");
        System.out.println(document);
        System.out.println("===============");

        //2.parse​(String html)：解析xml或html字符串
        String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "\n" +
                "<studnets>\n" +
                "    <student number=\"heima_0001\">\n" +
                "        <name>tom</name>\n" +
                "        <age>18</age>\n" +
                "        <sex>male</sex>\n" +
                "\n" +
                "    </student>\n" +
                "\n" +
                "    <student number=\"heima_0002\">\n" +
                "        <name>jack</name>\n" +
                "        <age>18</age>\n" +
                "        <sex>female</sex>\n" +
                "    </student>\n" +
                "    \n" +
                "</studnets>";
        Document document2 = Jsoup.parse(str);
        System.out.println(document2);

        //3.parse​(URL url, int timeoutMillis)：通过网络路径获取指定的html或xml的文档对象
        URL url = new URL("https://www.bilibili.com/video/BV11741127ic?p=103");//代表网络中的一个资源路径
        Document document3 = Jsoup.parse(url, 10000);
        System.out.println(document3);


    }
}
